package com.linkhouse.controller;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("authCode")
public class SendController {


    @Resource
    private Client client;



    @RequestMapping("sendMassage")
    @ResponseBody
    public String sendMassage(String phoneNum) throws Exception {
        String s = RandomStringUtils.randomNumeric(4);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(phoneNum)
                .setSignName("东科创想")
                .setTemplateCode("SMS_162522027")
                .setTemplateParam("{\"sms_code\":\""+s+"\"}");
        // 复制代码运行请自行打印 API 的返回值
        try {
            client.sendSms(sendSmsRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return s;
    }


}
